/**
 * 
 */
package billing;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.HashMap;

/**
 * RemoteObject for BillingServerSecure
 * @author Gernot
 *
 */
public class SecureBillingServer extends UnicastRemoteObject implements
        BillingServerSecure {
    protected SecureBillingServer() throws RemoteException {
        super();
    }
    private static final long serialVersionUID = 1L; 
   // private BillingManager bm = new BillingManager();
    private PriceSteps ps = new PriceSteps();
    private HashMap<String,BillData> bills = new HashMap<String,BillData>();
    
    @Override
    public PriceSteps getPriceSteps() throws RemoteException {
        return ps;
    }

    @Override
    public void createPriceStep(double startPrice, double endPrice,
            double fixedPrice, double variablePricePercent)
            throws RemoteException {
        ps.addPriceStep(startPrice, endPrice, fixedPrice, variablePricePercent);
    }

    @Override
    public void deletePriceStep(double startPrice, double endPrice)
            throws RemoteException {
        ps.removePriceStep(startPrice, endPrice);
    }

    @Override
    public void billAuction(String user, long auctionID, double price)
            throws RemoteException {
       BillData data = bills.get(user);
       if (data == null) {
          data = new BillData();
          bills.put(user, data);
       }
       data.addAuction(auctionID, price);
    }

    @Override
    public Bill getBill(String user) throws RemoteException {
        BillData data = bills.get(user);
        if (data!=null){
          return data.createBill(ps);
        } else {
          return new Bill("No Bill for User:"+user);  
        }
    }

}
